package org.acghub.mtdb.demo.bean;

/**
* xmlgen自动生成，不要修改此文件！！！
*/
public final class Person extends org.acghub.mtdb.core.TBean {
	private Long id;

	private String name;

	private Integer age;

	private Byte gender;

	private Pet pet;

	private java.util.List<Pet> petList;

	private java.util.Map<Long, Pet> petMap;

	public Person(org.acghub.mtdb.core.TBean _xp_, String _vn_) {
		super(_xp_, _vn_);
	}

	public Person() {
		this(null, null);
	}

	@Override
	protected void onConstructor() {
		this.id = 0L;
		this.name = "";
		this.age = 0;
		this.gender = 0;
		this.pet = new Pet(this, "pet");
		this.petList = new java.util.LinkedList<>();
		this.petMap = new java.util.HashMap<>();
	}

	public Long getId() {
		this._verify_unsafe_("getId", true);
		return this.id;
	}
	public String getName() {
		this._verify_unsafe_("getName", true);
		return this.name;
	}
	public Integer getAge() {
		this._verify_unsafe_("getAge", true);
		return this.age;
	}
	public Byte getGender() {
		this._verify_unsafe_("getGender", true);
		return this.gender;
	}
	public Pet getPet() {
		this._verify_unsafe_("getPet", true);
		return this.pet;
	}
	public java.util.List<Pet> getPetList() {
		if (org.acghub.mtdb.core.Transaction.isActive()) {
			return org.acghub.mtdb.core.Logs.list(this, "petList", this.petList, this._verify_unsafe_("getPetList", true));
		} else {
			return this.petList;
		}
	}
	public java.util.Map<Long, Pet> getPetMap() {
		if (org.acghub.mtdb.core.Transaction.isActive()) {
			return org.acghub.mtdb.core.Logs.map(this, "petMap", this.petMap, this._verify_unsafe_("getPetMap", true));
		} else {
			return this.petMap;
		}
	}
	public Person setId(Long v) {
		java.lang.Runnable _verify_ = this._verify_unsafe_("setId", false);
		if (java.util.Objects.equals(this.id, v)) {
			return this;
		}
		org.acghub.mtdb.core.Logs.simple(this, "id", this.id, _verify_);
		this.id = v;
		return this;
	}
	public Person setName(String v) {
		java.lang.Runnable _verify_ = this._verify_unsafe_("setName", false);
		if (java.util.Objects.equals(this.name, v)) {
			return this;
		}
		org.acghub.mtdb.core.Logs.simple(this, "name", this.name, _verify_);
		this.name = v;
		return this;
	}
	public Person setAge(Integer v) {
		java.lang.Runnable _verify_ = this._verify_unsafe_("setAge", false);
		if (java.util.Objects.equals(this.age, v)) {
			return this;
		}
		org.acghub.mtdb.core.Logs.simple(this, "age", this.age, _verify_);
		this.age = v;
		return this;
	}
	public Person setGender(Byte v) {
		java.lang.Runnable _verify_ = this._verify_unsafe_("setGender", false);
		if (java.util.Objects.equals(this.gender, v)) {
			return this;
		}
		org.acghub.mtdb.core.Logs.simple(this, "gender", this.gender, _verify_);
		this.gender = v;
		return this;
	}
	@Override
	public org.bson.Document marshal(org.bson.Document writer) {
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.id)) {
			writer.append("id", this.id);
		}
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.name)) {
			writer.append("name", this.name);
		}
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.age)) {
			writer.append("age", this.age);
		}
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.gender)) {
			writer.append("gender", this.gender);
		}
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.pet)) {
			org.bson.Document _writer_ = new org.bson.Document();
			this.pet.marshal(_writer_);
			writer.append("pet", _writer_);
		}
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.petList)) {
			java.util.List<org.bson.Document> _list_ = new java.util.ArrayList<>();
			for (Pet _v_: this.petList) {
				org.bson.Document _writer_ = new org.bson.Document();
				_v_.marshal(_writer_);
				_list_.add(_writer_);
			}
			writer.append("petList", _list_);
		}
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.petMap)) {
			org.bson.Document _writer_ = new org.bson.Document();
			for (java.util.Map.Entry<Long, Pet> _entry_ : this.petMap.entrySet()) {
				String _key_ = String.valueOf(_entry_.getKey());
				org.bson.Document _value_ = new org.bson.Document();
				_entry_.getValue().marshal(_value_);
				_writer_.append(_key_, _value_);
			}
			writer.append("petMap", _writer_);
		}
		return writer;
	}

	@Override
	public void unmarshal(org.bson.Document reader) {
		if (reader.containsKey("id")) {
			this.id = reader.get("id", Long.class);
		}
		if (reader.containsKey("name")) {
			this.name = reader.get("name", String.class);
		}
		if (reader.containsKey("age")) {
			this.age = reader.get("age", Integer.class);
		}
		if (reader.containsKey("gender")) {
			this.gender = reader.get("gender", Number.class).byteValue();
		}
		if (reader.containsKey("pet")) {
			org.bson.Document _reader_ = reader.get("pet", org.bson.Document.class);
			this.pet.unmarshal(_reader_);
		}
		if (reader.containsKey("petList")) {
			java.util.List<org.bson.Document> _list_ = reader.getList("petList", org.bson.Document.class);
			for (org.bson.Document _reader_ : _list_) {
				Pet _v_ = new Pet(this, "petList");
				_v_.unmarshal(_reader_);
				this.petList.add(_v_);
			}
		}
		if (reader.containsKey("petMap")) {
			org.bson.Document _map_reader_ = reader.get("petMap", org.bson.Document.class);
			for (String _str_key_ : _map_reader_.keySet()) {
				Long _key_ = org.acghub.mtdb.common.ObjectUtil.convert(_str_key_, Long.class);
				org.bson.Document _reader_ = _map_reader_.get(_str_key_, org.bson.Document.class);
				Pet _value_ = new Pet(this, "petMap");
				_value_.unmarshal(_reader_);
				this.petMap.put(_key_, _value_);
			}
		}
	}

	@Override
	public com.alibaba.fastjson2.JSONObject marshal(com.alibaba.fastjson2.JSONObject writer) {
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.id)) {
			writer.put("id", this.id);
		}
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.name)) {
			writer.put("name", this.name);
		}
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.age)) {
			writer.put("age", this.age);
		}
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.gender)) {
			writer.put("gender", this.gender);
		}
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.pet)) {
			com.alibaba.fastjson2.JSONObject _writer_ = new com.alibaba.fastjson2.JSONObject();
			this.pet.marshal(_writer_);
			writer.put("pet", _writer_);
		}
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.petList)) {
			java.util.List<com.alibaba.fastjson2.JSONObject> _list_ = new java.util.ArrayList<>();
			for (Pet _v_: this.petList) {
				com.alibaba.fastjson2.JSONObject _writer_ = new com.alibaba.fastjson2.JSONObject();
				_v_.marshal(_writer_);
				_list_.add(_writer_);
			}
			writer.put("petList", _list_);
		}
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.petMap)) {
			com.alibaba.fastjson2.JSONObject _writer_ = new com.alibaba.fastjson2.JSONObject();
			for (java.util.Map.Entry<Long, Pet> _entry_ : this.petMap.entrySet()) {
				String _key_ = String.valueOf(_entry_.getKey());
				com.alibaba.fastjson2.JSONObject _value_ = new com.alibaba.fastjson2.JSONObject();
				_entry_.getValue().marshal(_value_);
				_writer_.put(_key_, _value_);
			}
			writer.put("petMap", _writer_);
		}
		return writer;
	}

	@Override
	public void unmarshal(com.alibaba.fastjson2.JSONObject reader) {
		if (reader.containsKey("id")) {
			this.id = reader.getLong("id");
		}
		if (reader.containsKey("name")) {
			this.name = reader.getString("name");
		}
		if (reader.containsKey("age")) {
			this.age = reader.getInteger("age");
		}
		if (reader.containsKey("gender")) {
			this.gender = reader.getByte("gender");
		}
		if (reader.containsKey("pet")) {
			com.alibaba.fastjson2.JSONObject _reader_ = reader.getJSONObject("pet");
			this.pet.unmarshal(_reader_);
		}
		if (reader.containsKey("petList")) {
			java.util.List<com.alibaba.fastjson2.JSONObject> _list_ = reader.getList("petList", com.alibaba.fastjson2.JSONObject.class);
			for (com.alibaba.fastjson2.JSONObject _reader_ : _list_) {
				Pet _v_ = new Pet(this, "petList");
				_v_.unmarshal(_reader_);
				this.petList.add(_v_);
			}
		}
		if (reader.containsKey("petMap")) {
			com.alibaba.fastjson2.JSONObject _map_reader_ = reader.getJSONObject("petMap");
			for (String _str_key_ : _map_reader_.keySet()) {
				Long _key_ = org.acghub.mtdb.common.ObjectUtil.convert(_str_key_, Long.class);
				com.alibaba.fastjson2.JSONObject _reader_ = _map_reader_.getJSONObject(_str_key_);
				Pet _value_ = new Pet(this, "petMap");
				_value_.unmarshal(_reader_);
				this.petMap.put(_key_, _value_);
			}
		}
	}

	@Override
	public int hashCode() {
		int hash = this.getObjId().intValue();
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.id)){
			hash ^= org.acghub.mtdb.common.ObjectUtil.hashCode(this.id);
		}
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.name)){
			hash ^= org.acghub.mtdb.common.ObjectUtil.hashCode(this.name);
		}
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.age)){
			hash ^= org.acghub.mtdb.common.ObjectUtil.hashCode(this.age);
		}
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.gender)){
			hash ^= org.acghub.mtdb.common.ObjectUtil.hashCode(this.gender);
		}
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.pet)){
			hash ^= org.acghub.mtdb.common.ObjectUtil.hashCode(this.pet);
		}
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.petList)){
			hash ^= org.acghub.mtdb.common.ObjectUtil.hashCode(this.petList);
		}
		if (org.acghub.mtdb.common.ObjectUtil.nonNull(this.petMap)){
			hash ^= org.acghub.mtdb.common.ObjectUtil.hashCode(this.petMap);
		}
		return hash;
	}

	@Override
	public boolean equals(Object o) {
		if (null == o || !getClass().equals(o.getClass())) { return false; }
		if (this == o) { return true; }
		Person that = (Person) o;
		if (!org.acghub.mtdb.common.ObjectUtil.equals(this.id, that.id)) { return false; }
		if (!org.acghub.mtdb.common.ObjectUtil.equals(this.name, that.name)) { return false; }
		if (!org.acghub.mtdb.common.ObjectUtil.equals(this.age, that.age)) { return false; }
		if (!org.acghub.mtdb.common.ObjectUtil.equals(this.gender, that.gender)) { return false; }
		if (!org.acghub.mtdb.common.ObjectUtil.equals(this.pet, that.pet)) { return false; }
		if (!org.acghub.mtdb.common.ObjectUtil.equals(this.petList, that.petList)) { return false; }
		if (!org.acghub.mtdb.common.ObjectUtil.equals(this.petMap, that.petMap)) { return false; }
		return true;
	}
	@Override
	public String toString() {
		return new java.util.StringJoiner(", ", "Person[", "]")
				.add("id=" + id)
				.add("name=" + name)
				.add("age=" + age)
				.add("gender=" + gender)
				.add("pet=" + pet)
				.add("petList=" + petList)
				.add("petMap=" + petMap)
				.toString();
	}
}

